package com.gaohui.nestedrecyclerview.java;

import android.graphics.Color;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.viewpager2.widget.ViewPager2;

import android.view.View;
import android.widget.Toast;

import com.gaohui.nestedrecyclerview.BaseMenuActivity;
import com.gaohui.nestedrecyclerview.R;
import com.gaohui.nestedrecyclerview.java.adapter.HomeVpAdapter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainJavaActivity extends BaseMenuActivity {

    private ViewPager2 mVpHomeArea;
    private HomeVpAdapter mHomeVpAdapter;

    Long lastBackPressedTime = 0L;



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_java);

        mVpHomeArea = findViewById(R.id.vp_home_area);
        mHomeVpAdapter = new HomeVpAdapter(this, getTestData());
        mVpHomeArea.setAdapter(mHomeVpAdapter);


        findViewById(R.id.tvBack).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //todo xfhy 待实现
//                javaRecyclerView.scrollToPosition(0);
//                javaRecyclerView.setCanScrollVertically(true);
                findViewById(R.id.cl_title).setVisibility(View.GONE);
            }
        });
    }

    private List<Fragment> getTestData() {
        //todo xfhy 测试

        List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            fragments.add(WeatherFragment.newInstance());
        }
        return fragments;
    }

    @Override
    public void onBackPressed() {
        if (System.currentTimeMillis() - lastBackPressedTime < 2000) {
            super.onBackPressed();
        } else {
            //todo xfhy 待实现
            //javaRecyclerView.scrollToPosition(0);
            //javaRecyclerView.setCanScrollVertically(true);
            Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
            lastBackPressedTime = System.currentTimeMillis();
        }
    }

}
